package com.lyh.hkcloud.module.common;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.lyh.hkcloud.R;
import com.lyh.hkcloud.base.BaseActivity;

/**
 * @author: zhongfan
 * @program: hkCloud
 * @description: 测试案例
 * @company—date: 利元数据 2022-02-21 16:10
 **/
public class DomeActivity extends BaseActivity implements View.OnClickListener {

    LinearLayout llBu;
    Button btDelete;
    Button btAdd;

    @Override
    protected Activity getActivity() {
        return null;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.test;
    }

    @Override
    protected void initView() {
        llBu = findViewById(R.id.ll_buju);
        btDelete = findViewById(R.id.bt_delete);
        btAdd = findViewById(R.id.bt_add);
        btDelete.setOnClickListener(this);
        btAdd.setOnClickListener(this);

    }


    public void addButton(){
        llBu.addView(createView(123));
    }

    public void deleteButton(){
        int count = llBu.getChildCount();
        System.out.println("count = " + count);
        llBu.removeViewAt(count-2);
    }

    protected View createView(Integer index) {//动态添加组件

        Button btn = new Button(this);//动态创建按钮

        btn.setId(index++);

        btn.setLayoutParams(new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT));

        btn.setText("aaaaaa" + index);

        return btn;

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_add:
                addButton();
                break;
            case R.id.bt_delete:
                deleteButton();
                break;
        }
    }
}
